<template>
  <el-dialog
    title="请写下你的问题，五胡四海的朋友来帮你解答"
    :visible.sync="dialogVisible"
    width="30%"style="font-weight: bold;"
  >
    <el-input placeholder="请写下你的问题" type="textarea" maxlength="300" :rows="6"
              show-word-limit
              v-model="question"
    ></el-input>
    <span slot="footer" class="dialog-footer">
    <el-button type="primary" :disabled="question == '' ? true : false" @click="AddQuestion()">发布问题</el-button>
  </span>
  </el-dialog>

</template>
<script>
  export default {
    components:{

    },
    data() {
      return {
        activeIndex: this.$route.path,
        dialogVisible: false,
        question: ''
      };
    },
    watch:{
      dialogVisible(val)
      {
        if(!val)
        {
          this.question=''
        }
      }
    },
    methods: {
      init()
      {
        this.dialogVisible=true;
      },
      AddQuestion()
      {
        if(this.question==''|| this.question==null)
        {
          this.$message({
            message:"请填写内容",
            type:'warning'
          })
          return
        }
        var params={
          content:this.question
        }
        this.$http.post("http://localhost:8989/fornote/question/createNewQuestion",params).then(response =>{
          // this.$forceUpdate();
          console.log(response.data);
          if(response.data.code==200)
          {
            this.$message({
              message:response.data.data,
              type:'success'
            })
            this.dialogVisible=false;
          }else if(response.data.code!=200)
          {
            this.$message({
              message:"新增问题失败",
              type:"error"
            })
          }

        })
      }
    }
  }
</script>

<style>
  .el-dialog .el-dialog__header {
    background: #2c89f8;
    border-top-left-radius: 6px;
    border-top-right-radius: 6px;
  }
  .el-dialog__title {
    color: #fff;
  }
</style>
